"""
项目配置文件

该模块包含项目的所有配置项，包括文件存储路径、清理策略、API配置等。
"""
import os
from pathlib import Path
from typing import Dict, Any

# 项目根目录
PROJECT_ROOT = Path(__file__).parent

# 文件存储配置
STORAGE_CONFIG = {
    # 证件照文件存储根目录
    "base_dir": PROJECT_ROOT / "openid",
    # 子目录配置
    "subdirs": {
        "original": "original",      # 原图
        "standard": "standard",      # 标准证件照
        "hd": "hd",                  # 高清证件照
        "transparent": "transparent",  # 透明背景证件照
        "transparent_hd": "transparent_hd",  # 透明背景高清证件照
        "layout": "layout",          # 排版证件照
        "social_media": "social_media"  # 社交媒体模板
    },
    # 文件命名格式
    "filename_format": "{timestamp}_{original_name}_{size}_{suffix}",
    # 支持的文件格式
    "supported_formats": [".png", ".jpg", ".jpeg"],
    # 文件大小限制 (MB)
    "max_file_size": 10
}

# 自动清理配置
CLEANUP_CONFIG = {
    # 文件保留时间 (天)
    "retention_days": 7,
    # 清理检查间隔 (小时)
    "cleanup_interval": 24,
    # 是否启用自动清理
    "auto_cleanup_enabled": True,
    # 清理日志文件
    "cleanup_log": PROJECT_ROOT / "logs" / "cleanup.log"
}

# API配置
API_CONFIG = {
    # Gradio API端点
    "gradio_endpoint": "https://swanlab-hivisionidphotos.ms.show/",
    # 请求超时时间 (秒)
    "request_timeout": 60,
    # 重试次数
    "max_retries": 3,
    # 重试间隔 (秒)
    "retry_interval": 5
}

# 日志配置
LOGGING_CONFIG = {
    # 日志级别
    "level": "INFO",
    # 日志文件路径
    "log_file": PROJECT_ROOT / "logs" / "app.log",
    # 日志格式
    "format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s",
    # 日志文件最大大小 (MB)
    "max_file_size": 50,
    # 日志文件备份数量
    "backup_count": 5
}

# 证件照尺寸配置
ID_PHOTO_SIZES = [
    {"name": "一寸", "dimensions": (413, 295), "description": "标准一寸证件照"},
    {"name": "二寸", "dimensions": (626, 413), "description": "标准二寸证件照"},
    {"name": "小一寸", "dimensions": (378, 260), "description": "小一寸证件照"},
    {"name": "小二寸", "dimensions": (531, 413), "description": "小二寸证件照"},
    {"name": "大一寸", "dimensions": (567, 390), "description": "大一寸证件照"},
    {"name": "大二寸", "dimensions": (626, 413), "description": "大二寸证件照"},
    {"name": "五寸", "dimensions": (1499, 1050), "description": "五寸证件照"},
    {"name": "教师资格证", "dimensions": (413, 295), "description": "教师资格证专用"},
    {"name": "国家公务员考试", "dimensions": (413, 295), "description": "公务员考试专用"},
    {"name": "初级会计考试", "dimensions": (413, 295), "description": "会计考试专用"},
    {"name": "英语四六级考试", "dimensions": (192, 144), "description": "英语等级考试专用"},
    {"name": "计算机等级考试", "dimensions": (567, 390), "description": "计算机等级考试专用"},
    {"name": "研究生考试", "dimensions": (709, 531), "description": "研究生考试专用"},
    {"name": "社保卡", "dimensions": (441, 358), "description": "社保卡专用"},
    {"name": "电子驾驶证", "dimensions": (378, 260), "description": "电子驾驶证专用"},
    {"name": "美国签证", "dimensions": (600, 600), "description": "美国签证专用"},
    {"name": "日本签证", "dimensions": (413, 295), "description": "日本签证专用"},
    {"name": "韩国签证", "dimensions": (531, 413), "description": "韩国签证专用"}
]

# 背景颜色配置
BACKGROUND_COLORS = [
    "蓝色", "白色", "红色", "黑色", "深蓝色", "浅灰色", 
    "美式证件照", "自定义(RGB)", "自定义(HEX)"
]

# 水印配置
WATERMARK_CONFIG = {
    "options": ["不添加", "添加"],
    "default_text": "",
    "default_color": "#FFFFFF",
    "default_size": 20,
    "default_opacity": 0.15,
    "default_angle": 30,
    "default_space": 25
}

# 语言支持
SUPPORTED_LANGUAGES = ["zh", "en", "ko", "ja"]

# 创建必要的目录
def create_directories():
    """创建项目所需的目录结构"""
    directories = [
        STORAGE_CONFIG["base_dir"],
        *[STORAGE_CONFIG["base_dir"] / subdir for subdir in STORAGE_CONFIG["subdirs"].values()],
        PROJECT_ROOT / "logs",
        CLEANUP_CONFIG["cleanup_log"].parent,
        LOGGING_CONFIG["log_file"].parent
    ]
    
    for directory in directories:
        directory.mkdir(parents=True, exist_ok=True)

# 初始化时创建目录
create_directories()